Restart psi-secrets after refresh so serve reloads fresh cache#35
Merged
Restart psi-secrets after refresh so serve reloads fresh cache#35
Conversation
Every time psi-{provider}-refresh.timer fires, setup re-registers
secrets via delete+create through the Podman API, which assigns fresh
hex IDs. Setup writes those new IDs to the on-disk cache file and the
prune step from PR #32 drops the old entries. But serve holds the
OLD cache in memory from its last startup and never picks up the new
file state — so every lookup after the first refresh goes straight to
the provider, and the cache does no work until an operator manually
restarts psi-secrets.
Observed on the test server: 1554 secret lookups over 30 minutes, zero
cache hits. All source=provider. The refresh timer had fired 7
minutes earlier and silently broke the cache.
Add a second ExecStart to the refresh wrapper that runs systemctl
try-restart psi-secrets.service after setup completes. try-restart is
a no-op if serve is not currently active, so this is safe on hosts
that have intentionally stopped psi-secrets.
There is a brief (~30s on HSM) lookup-fails-to-cache window during
the serve restart, but this happens at most once per
cache.refresh_interval (default 1h) instead of never.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Every time
psi-{provider}-refresh.timerfires, setup re-registers secrets via delete+create through the Podman API, which assigns fresh hex IDs. Setup writes those new IDs to the on-disk cache file and the prune step from PR #32 drops the old entries. But serve holds the OLD cache in memory from its last startup and never picks up the new file state — so every lookup after the first refresh goes straight to the provider, and the cache does no work until an operator manually restarts psi-secrets.Observed on the test server
1554 secret lookups over 30 minutes, zero cache hits. All
source: provider. The refresh timer had fired 7 minutes earlier and silently broke the cache. Victoria Logs flagged it via the sheer volume of provider-source events.Fix
Add a second
ExecStartto the refresh wrapper that runssystemctl try-restart psi-secrets.serviceafter setup completes.try-restartis a no-op if serve is not currently active, so this is safe on hosts that have intentionally stopped psi-secrets.There is a brief (~30s on HSM) lookup-fails-to-cache window during the serve restart, but this happens at most once per
cache.refresh_interval(default 1h) instead of never.Test plan
pytest tests/test_unitgen.py— new regression testtest_restarts_psi_secrets_so_serve_reloads_the_fresh_cache; all 52 unitgen tests pass.ruff check/ty check— clean.psi systemd installto regenerate the wrapper, fire the refresh, confirm Victoria Logs showssource: cacheentries going forward.Remaining issue (separate PR)
Victoria Logs classifies all PSI log entries as
level: errorbecause loguru writes to stderr and conmon maps stderr →PRIORITY: 3. Separate from this PR — a follow-up will split INFO/DEBUG to stdout (PRIORITY 6).